using Zhaoxi.Zhihu.Core.AppUserAggregate.Entites;

using Zhaoxi.Zhihu.Core.Interface;
using Zhaoxi.Zhihu.Core.QuestionAggregate.Entites;
using Zhaoxi.Zhihu.SharedKerel.Repositoy;
using Zhaoxi.Zhihu.SharedKerel.Result;

namespace Zhaoxi.Zhihu.Core.Service;

public class FollowQuestionService(IRepository<Question> followQuestionRepository):IFollowQuestionService
{
    public async Task<IResult> FollowAsync(AppUser appUser, int questionId, CancellationToken cancellation)
    {
        var question=await followQuestionRepository.GetByIdAsync(questionId, cancellation);
        
        if (question == null)return Result.NotFound("关注问题不存在");
        
        var result=appUser.AddFollowQuestion(questionId);
        return Result.From(result);
    }
}